<?php

/**
 * Plugin roundresult
 * @author Marko Bischof <joomlabasic@gmail.com>
 * @copyright Copyright &copy; 2006, Marko Bischof http://leagueman.joomlabasic.com
 * @package com_leagueman
 */

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$_MAMBOTS->registerFunction( 'onPrepareContent', 'show_clubinfo' );

function show_clubinfo( $published, &$row, &$params, $page ) {
	
	$regex = "#{(leagueman_clubinfo)\s*(.*?)}#";
	
	if(!$published) {
		$row->text = preg_replace($regex, "", $row->text);
	} else {
		$row->text = preg_replace_callback($regex, "clubinfo_replacer", $row->text);
	}
	
	return true;
}

function clubinfo_replacer(&$matches){
	global $mainframe, $Itemid;
	
	require_once $mainframe->getCfg("absolute_path") . '/includes/domit/xml_saxy_lite_parser.php';
	require_once $mainframe->getPath("class", "com_leagueman");
	
	$attribs = Saxy_Lite_Parser::parseAttributes($matches[2]);
	
	$c = $attribs["c"];
	
	$club = LM::getLMTable("Club");
	if(!$club->load($c)){
		return "no club data available";
	}
	
	$template = LM::getTemplate();

	$template->assign("club", $club);
	$template->assign("Itemid", $Itemid);
	
	return $template->fetch("clubinfo.tpl.php");
}

?>
